package operations;

import books.Book;
import books.BookList;

import java.util.Scanner;

public class ReturnOperation implements IOperation{
    @Override
    public void work(BookList bookList) {
        System.out.println("归还图书");

        System.out.println("请输入要归还的图书名");

        Scanner scanner = new Scanner(System.in);
        String name = scanner.nextLine();

        int currentSize = bookList.getUsedSize();

        for (int i = 0; i < currentSize; i++) {
            Book book = bookList.getPos(i);
            if(name.equals(book.getName())){
                book.setBorrowed(false);
                System.out.println("图书归还成功");
                break;
            }
        }
        System.out.println("要归还的图书不存在");
    }
}
